package com.example.bluetoothexample;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.apache.http.HttpResponse;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;

public class JSONParser {
	
	public JSONParser()
	{
		
	}
	
	public JSONObject getJSONFromResponse(HttpResponse response)
	{
		String json = "";
		JSONObject jObj = null;
		try
		{
			BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
			StringBuilder sb = new StringBuilder();
			String line = null;
			
			while((line = reader.readLine()) != null)
			{
				sb.append(line + "\n");
			}
			json = sb.toString();
		}
		catch(Exception e)
		{
			Log.e("SettingsActivity", "getJSONFromResponse: " + e.getMessage());
		}
		
		try
		{
			jObj = new JSONObject(json);
		}
		catch(JSONException e)
		{
			Log.e("SettingsActivity", "getJSONFromResponse exp2: " + e.getMessage());
		}
		
		return jObj;
	}
}
